﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RearLivestock.Beginning.Api.Application.Command.PigDeath;
using RearLivestock.Common.Dtos;

namespace RearLivestock.Beginning.Api.Controllers
{
    /// <summary>
    /// 猪只死亡控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PigDeathsController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public PigDeathsController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 猪只死亡添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddPigDeath(AddPigDeathCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 死亡原因列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> GetDeathReasons(GetDeathReasonsCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 猪只死亡列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result<PageResultDto<PigDeathDto>>> QueryPigDeath(QueryPigDeathCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 猪只死亡删除
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<Result> DelPigDeath(DelPigDeathCommand cmd)
        {
            return await mediator.Send(cmd);
        }
    }
}
